import sys

BACK = 'b'
FRONT = 'f'
SPEP = 's'
UNKNOWN = 'u'


class AABB(object):

    def __init__(self, xmin, xmax, ymin, ymax):
        super(AABB, self).__init__()
        # 坐标系是倾斜的
        #      o (0, 0)
        #    /   \
        #   /     \
        #  /       \
        # x         y
        self.xmin, self.xmax, self.ymin, self.ymax = xmin, xmax, ymin, ymax

    def __str__(self):
        return f'{self.xmin}, {self.xmax}, {self.ymin}, {self.ymax}]'


def compare_line_section(ab1, ab2):
    l1v = ab1.ymin - ab1.xmax
    r1v = ab1.ymax - ab1.xmin
    l2v = ab2.ymin - ab2.xmax
    r2v = ab2.ymax - ab2.xmin

    if (r1v < l2v) or (r2v < l1v):
        return SPEP

    l1u = ab1.xmax + ab1.ymin
    r1u = ab1.xmin + ab1.ymax

    l2u = ab2.xmax + ab2.ymin
    r2u = ab2.xmin + ab2.ymax

    if max(l1u, r1u) < min(l2u, r2u):
        return BACK
    if min(l1u, r1u) > max(l2u, r2u):
        return FRONT

    # 相等的时候再次计算
    d1v = r1v - l1v
    d2v = r2v - l2v
    d1u = r1u - l1u
    d2u = r2u - l2u

    # k2 - k1
    det = d1u * d2v - d2u * d1v
    if abs(det) < 0.01:
        dv = l2v - l1v
        du = l2u - l1u
        d = dv * d1u - du * d1v
        if d < -0.001:
            return BACK
        if d > 0.001:
            return FRONT

        if l1v < l2v:
            return BACK
        if l1v > l2v:
            return FRONT

        if r1v > r2v:
            return BACK
        if r1v < r2v:
            return FRONT

        return UNKNOWN

    dv = l2v - l1v
    du = l2u - l1u
    e1 = (d2v * du - d2u * dv) / det
    e2 = (d1v * du - d1u * dv) / det

    d = 0
    if e1 < 0:
        d = dv * d2u - du * d2v
    elif e1 > 1:
        d = (r1u - l2u) * d2v + (l2v - r1v) * d2u
    elif e2 < 0:
        d = dv * d1u - du * d1v
    elif e2 > 1:
        d = (l1u - r2u) * d1v + (r2v - l1v) * d1u

    # print(e1, e2, d, det, d1v, d1u, d2v, d2u, dv, du)
    if d < 0:
        return BACK

    if d > 0:
        return FRONT

    return UNKNOWN


def compare_center_y(ab1, ab2):
    cx1 = (ab1.xmax + ab1.xmin) / 2
    cy1 = (ab1.ymax + ab1.ymin) / 2

    cx2 = (ab2.xmax + ab2.xmin) / 2
    cy2 = (ab2.ymax + ab2.ymin) / 2

    d = (cx1 + cy1) - (cx2 + cy2)
    print('##', d, cx1, cy1, cx2, cy2)
    if d < 0:
        return BACK
    if d > 0:
        return FRONT
    d = (cx1 - cy1) - (cx2 - cy2)
    print('###', d, cx1, cy1, cx2, cy2)
    if d < 0:
        return BACK
    if d > 0:
        return FRONT
    return SPEP


def compare(ab1: AABB, ab2: AABB):
    relation = compare_line_section(ab1, ab2)
    return compare_center_y(ab1, ab2) if (relation == UNKNOWN) else relation


ab1 = AABB(float(sys.argv[1]), float(sys.argv[2]), float(sys.argv[3]),
           float(sys.argv[4]))
ab2 = AABB(float(sys.argv[5]), float(sys.argv[6]), float(sys.argv[7]),
           float(sys.argv[8]))

print(compare(ab1, ab2))
